<?php

/**
 * Strip tags out, normalize text
 * @param <type> $content
 * @return <type>
 */
function str_normalize($content) {
	$content = strip_tags($content);

	$p = array(
		 '/&shy;|&#173;|&#xAD;|&#x200B;|&#x200D;|&#8203;/i',
		 '/[\x{00ad}\x{200b}\x{200d}]/u',
		 '/&nbsp;|&#8208;|&#8210;|&ndash;|&#8211;|&mdash;|&#8212;|&#8213;|&#8275;/i',
		 '/[!\?;:\"\'`“”^\*\+\-_\(\)\[\]\{\}#@&~\.,\\\\\/\|]/',
		 '/\s+/'
	);
	$r = array('', '', ' ', ' ', ' ');
	$content = preg_replace($p, $r, $content);

	$s = array('[',']','-');
	$content = str_replace($s,' ',$content); //Dirty hack to prevent Roti's exception.

	return $content;
}

/**
 * Make text 300 characters long
 * (summary-like that somehow represents the fulltext)
 * @param <type> $content
 * @return <type>
 */
function str_summarize($content) {
	$content_short = $content;
	$len = mb_strlen($content);
	if ($len > 300) {
		$content_top    = mb_substr($content, 0, 199);
		$content_bottom = mb_substr($content, -100);
		$content_short  = $content_top.' '.$content_bottom;
	}

	return $content_short;
}

?>
